package cn.buk.tms.dao;

import cn.buk.tms.dto.AuthInfo;
import cn.buk.tms.entity.bill.*;
import cn.buk.tms.entity.misc.*;
import cn.buk.tms.sc.SearchBillInfoCriteria;
import cn.buk.tms.sc.SearchFlightOrderCriteria;
import cn.buk.tms.sc.SearchReceiptCriteria;

import java.util.Date;
import java.util.List;

/**
 * @author yfdai
 */
public interface BillDao {

  BillInfo getBillInfo(int id);

  BillInfo getBillInfo(int id, boolean fetchChild);

  int changeBillCustomer(int enterpriseId, String username, int billId, int customerId, String costCenter, String projectName);

  int createFlightBill(BillInfo billInfo, int flightOrderId);

  int createFlightRefundBill(BillInfo billInfo);

  int createFlightChangeBill(BillInfo billInfo);

  int createVasBill(BillInfo billInfo);

  List<BillInfo> searchBillInfos(int enterpriseId, int flightOrderId);

  List<BillInfo> searchBillInfos(int enterpriseId, String orderNo, String billType);

  List<BillInfo> searchMyBillInfo(int enterpriseId, SearchBillInfoCriteria sc);

  List<BillInfo> searchBillInfoBySettlementNo(int enterpriseId, String settlementNo, String billNum,
                                              String orderNo, Date billDate, String flightOrderNo, String psgName);

  List<BillInfo> searchBillInfoNotProcessed(int max);

  int deleteBillInfo(int enterpriseId, int billId);

  /**
   * 根据账单号搜索账单对应的机票
   *
   * @param enterpriseId 企业id
   * @param billNum      账单号
   * @return 账单对应的机票信息
   */
  List<BillFlightTicket> searchBillFlightTickets(int enterpriseId, String billNum);

  /**
   * 根据账单号搜索对应的退票
   */
  List<BillFlightRefundTicket> searchBillFlightRefundTickets(int enterpriseId, String billNum);

  List<BillFlightRefundTicket> searchBillFlightRefundTickets(int enterpriseId, List<String> billNums);

  /**
   * 根据账单号搜索对应的改签
   */
  List<BillChangeOrder> searchBillChangeOrders(int enterpriseId, String billNum);

  List<BillChangeOrder> searchBillChangeOrders(int enterpriseId, List<String> billNums);

  /**
   * 根据账单号搜索对应的服务单
   */
  List<BillVasOrder> searchBillVasOrders(int enterpriseId, String billNum);

  List<BillVasOrder> searchBillVasOrders(int enterpriseId, List<String> billNums);

  /**
   * 根据账单号搜索对应的火车票
   */
  List<BillTrainTicket> searchBillTrainTickets(int enterpriseId, String billNum);

  List<BillTrainTicket> searchBillTrainTickets(int enterpriseId, List<String> billNums);

  /**
   * 根据账单号搜索对应的酒店
   */
  List<BillHotelBooking> searchBillHotelBookings(int enterpriseId, String billNum);

  List<BillHotelBooking> searchBillHotelBookings(int enterpriseId, List<String> billNums);


  /**
   * 根据结算单号查找对应的机票
   */
  List<BillFlightTicket> searchBillFlightTicketsBySettlementNo(int enterpriseId, String settlementNo, String psgName, String ticketNo);

  /**
   * 查找未审核账单的机票
   *
   * @param enterpriseId 企业id
   * @param sc           查找条件
   * @param status       0-未审核的，1-已审核的
   * @return 符合要求的票号
   */
  List<BillFlightTicket> searchBillFlightTickets(int enterpriseId, SearchFlightOrderCriteria sc, int status);


  List<BillTrainTicket> searchTrainTickets(int enterpriseId, SearchBillInfoCriteria sc);

  BillInfo getBillInfo(int enterpriseId, String billNum);

  int createTrainTicket(int enterpriseId, String username, BillTrainTicket ticket, BillInfo billInfo);

  int createHotelBooking(int enterpriseId, String username, BillHotelBooking ticket, BillInfo billInfo);

  List<BillHotelBooking> searchHotelBookings(int enterpriseId, SearchBillInfoCriteria sc);


  int auditBillInfoDone(int enterpriseId, String username, int billId, String remark);

  int cancelBillInfoAuditPassed(int enterpriseId, String operator, int id, String remark);

  int batchReviewBillInfos(int enterpriseId, String username, int[] billIds, double total);

  /**
   * 自动审核账单
   *
   * @param enterpriseId 企业id
   * @param username     用户名
   * @param billId       账单id
   * @param ticketStatus TicketSale中的票类型
   */
  int autoReviewBillInfo(int enterpriseId, String username, int billId, int ticketStatus);


  /**
   * 收款单对账单进行销账
   *
   * @param receiptId         收款单id
   * @param billId            账单id
   * @param operator          操作员
   * @param ignoreNegativeNum 是否忽略负数
   */
  int writeOffBill(int receiptId, int billId, String operator, final boolean ignoreNegativeNum);

  /**
   * 超级管理员直接对账单进行销账
   */
  int writeOffBill(int enterpriseId, int userId, int billId);


  /**
   * 将账单信息金额同步到 企业余额表
   *
   * @param enterpriseId  授信企业id
   * @param customerEntId 被授信企业id
   * @param id            账单id
   * @param billNum       账单号
   * @param billSum       账单金额
   */
  void syncBillInfo2Balance(int enterpriseId, int customerEntId, int id, String billNum, int billSum);

  List<OperationLog> searchBillInfoHistory(int enterpriseId, int id);

  int updateBillSupplier(int enterpriseId, String username, int billId, Supplier supplier);

  int updateBillInfoPayment(int enterpriseId, String username, int billId, PaymentMethod pm);

  int updateBillInfoEtdzDate(int enterpriseId, String username, int billId, Date etdzDate);

  //修改账单日期
  int updateBillInfoOpDate(int enterpriseId, String username, int billId, Date opDate);

  int updateBillInfoOp1(int enterpriseId, String username, int billId, String op1);

  int updateBillInfoRemark(int enterpriseId, String username, int billId, String remark);

  int updateBillInfoPayType(int enterpriseId, String username, int billId, String payType);


  List<ReceiptHistory> searchReceiptHistory2(int enterpriseId, int id);

  /**
   * 创建收款单
   */
  int createReceiptInfo(int enterpriseId, int customerEnterpriseId, ReceiptInfo info, Integer[] receiptIds);

  /**
   * 使用支付宝账户账务明细创建收款单
   */
  int createReceiptInfoByAlipayBillAccountLog(int enterpriseId, String username, ReceiptInfo info, int alipayBillAccountLogId);

  ReceiptInfo refreshReceiptInfo(int id);

  /**
   * 删除收款单
   */
  int deleteReceipt(int enterpriseId, String username, int id);

  int refundReceipt(int enterpriseId, String username, int id, double amount, String remark);

  int updateReceiptRemark(int enterpriseId, String username, int id, String remark);

  List<ReceiptInfo> searchReceipts(int enterpriseId, SearchReceiptCriteria sc, List<Integer> allowedCustomerIds);

  int checkBillIntlTicket(int enterpriseId);

  /**
   * 查找账单（机票、改签、退票）的航司代码为空的账单
   */
  List<BillInfo> searchBillByAirlinesIsNull(String billType, int max);

  /**
   * 修改账单信息中的carrier字段
   */
  void updateBillInfoAirlines(int id, String twoCode);


  /**
   * 根据结算单号查找机票信息
   */
  List<BillFlightTicket> searchTicketsBySettlementNo(int enterpriseId, String settlementNo);

  /**
   * 根据结算单号查找退票
   */
  List<BillFlightRefundTicket> searchRefundsBySettlementNo(int enterpriseId, String settlementNo);

  /**
   * 根据结算单号查找改签
   */
  List<BillChangeOrder> searchChangesBySettlementNo(int enterpriseId, String settlementNo);

  /**
   * 根据结算单号查找服务单
   */
  List<BillVasOrder> searchVasOrdersBySettlementNo(int enterpriseId, String settlementNo);

  /**
   * 根据结算单号查找服务单
   */
  List<BillHotelBooking> searchHotelOrdersBySettlementNo(int enterpriseId, String settlementNo);

  /**
   * 根据结算单号查找服务单
   */
  List<BillTrainTicket> searchTrainTicketsBySettlementNo(int enterpriseId, String settlementNo);

  /**
   * 根据结算单号查找租车账单
   */
  List<BillRentalCarOrder> searchBillRentalCarsBySettlementNo(int enterpriseId, String settlementNo);

  void updateBillRefundTicketPnrNo(String agentName);

  /**
   * 将服务订单中的route_detail 填上合适的数据
   */
  void updateBillVasRouteDetail(String agentName);

  int updateBillVasPsgCount(String agentName);


  /**
   * 撤销账单销账
   */
  int undoWriteOffBill(int enterpriseId, String username, int billId);

  /**
   * 更新火车票账单的人数
   */
  int updateTrainBillPsgCount(String agentName);

  /**
   * 完成支付
   */
  int updateBillPaymentStatus(int enterpriseId, int userId, int id, int paymentStatus);

  /**
   * 生成租车账单
   */
  int createRentalCarBill(BillInfo billInfo, int orderId);

  List<BillRentalCarOrder> searchBillCarOrders(int enterpriseId, String billNum);

  /**
   * 根据乘机人姓名查找原订单号
   */
  List<String> searchBillFlightOrderNos(int enterpriseId, String likePsgName);


  List<BillInfo> searchSupplierIsNull(int enterpriseId);

  int updateBillSupplierAndPaymentMethod(int enterpriseId, String username, int id, Supplier supplier, PaymentMethod pm);

  BillInfo getBillInfoByIdOrNo(int enterpriseId, Integer billId, String billNo);

  int createAlipayBillAccountLog(int enterpriseId, String username, AlipayBillAccountLog log);

  int updateReceiptCustomer(int enterpriseId, String username, int receiptId, int customerId);

  /**
   * 合并收款单
   * @return
   */
  int mergeReceipts(AuthInfo authInfo, Integer[] receiptIds);
}
